<?php

use yii\helpers\Url;

?>
<div>

    <form class="form-inline" id="modaledit_submit_form" method="post" enctype="multipart/form-data"
          action="edit-goods-extend-category" target="upload_exec_target">
        <div class="form-group">
            <input type="hidden" name="edit_id" class="form-control" value="<?= $detail ? $detail['id'] : '' ?>">
            <input type="hidden" name="edit_institution_code" class="form-control"
                   value="<?= $institution_code ?>">

            <label>分类名称：</label>
            <input type="text" name="edit_name" class="form-control" value="<?= $detail ? $detail['name'] : '' ?>"
                   style="width: 470px">
        </div>
        <div class="form-group" style=" margin-top: 6px">
            <label>&nbsp;&nbsp;&nbsp;标识符：</label>
            <input type="text" name="edit_identifier_code" class="form-control" placeholder="标识符"
                   value="<?= $detail ? $detail['identifier_code'] : '' ?>" style="width: 470px">
        </div>
        <div class="form-group" style=" margin-top: 6px">
            <label>终端类型：</label>
            <select id="edit_endpoint" name="edit_endpoint" class="form-control" style=" width: 470px"
                    onchange="">
                <option value="wap">wap</option>
                <option value="pc">pc</option>
            </select>
        </div>
        <div class="form-group" style=" margin-top: 6px">
            <label>分类类型：</label>
            <select id="edit_type" name="edit_type" class="form-control" style=" width: 470px"
                    onchange="">
                <option value="1">专题活动</option>
                <option value="2">商品分类</option>
            </select>
        </div>
        <div class="form-group" style=" margin-top: 6px">
            <label>分类图片：</label>
            <input type="text" name="edit_image_url" class="form-control" style="width: 470px;"
                   readOnly="true" value="<?= $detail ? $detail['image_url'] : '' ?>">
            <input id="edit_image_file" name="edit_image_file" type="file"/>
            <img id="img_image_url" name="img_image_url" src="<?= $detail ? $detail['image_url'] : '' ?>" class="img-responsive"
                 style="display: none;width:150px;margin-left: 75px;"/>

        </div>

        <div class="form-group" style=" margin-top: 6px">
            <label>链接地址：</label>
            <input type="text" id="edit_link_url" name="edit_link_url" value="<?= $detail ? $detail['link_url'] : '' ?>"
                   class="form-control" style="width: 470px;">
        </div>
        <div class="form-group" style=" margin-top: 6px">
            <label>概要描述：</label>
            <textarea name="edit_summary" class="form-control" style="width: 470px;"
                      rows="3"><?= $detail ? $detail['summary'] : '' ?></textarea>
        </div>
        <div class="form-group" style=" margin-top: 6px">
            <label>是否启用：</label>
            <select id="edit_is_enabled" name="edit_is_enabled" class="form-control" style=" width: 470px" onchange="">
                <option value="1">启用</option>
                <option value="0">禁用</option>
            </select>
        </div>
        <div class="form-group" style=" margin-top: 6px">
            <label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;备注：</label>
            <textarea name="edit_remark" class="form-control" style="width: 470px;"
                      rows="3"><?= $detail ? $detail['remark'] : '' ?></textarea>
        </div>
    </form>
    <iframe id="upload_exec_target" name="upload_exec_target" style="display: none;"></iframe>

</div>
<script>
    $('#edit_image_file').change(function (event) {
        var files = event.target.files;
        if (files && files.length > 0) {
            file = files[0];
            //console.log(file);
            if (file.size > 1024 * 1024 * 2) {
                $(this).val('');
                $("#img_image_url").attr("src", '');
                alert('图片大小不能超过 2MB!');
                return false;
            }
            var URL = window.URL || window.webkitURL;
            var imgURL = URL.createObjectURL(file);
            $("#img_image_url").attr("src", imgURL);
            $("#img_image_url").show();
        }
    });
    var v_type = <?=$detail ? $detail['type'] : '1' ?>;
    var v_is_enabled = <?=$detail ? $detail['is_enabled'] : '1' ?>;
    var v_endpoint = '<?=$detail ? $detail['endpoint'] : '' ?>';
    (function () {
        $('#edit_type').val(v_type);
        $('#edit_is_enabled').val(v_is_enabled);
        $('#edit_endpoint').val(v_endpoint);
        $('#edit_link_url').hide();
        if ($('#edit_type').val() == '1') {
            $('#edit_link_url').show();
        }
        $('#edit_type').change(function (event) {
            $('#edit_link_url').hide();
            if ($('#edit_type').val() == '1') {
                $('#edit_link_url').show();
            }
        });
    })();
</script>
